/*
@author   : wang lingcong
@date     : 2022/11/01
@desc     : react error boundary
*/
import * as React from 'react'
import { ErrorPage } from './home/error'
interface Props {
  children?: React.ReactNode
}
interface State {
  hasError: boolean
}
class ErrorBoundary extends React.Component<Props, State> {
  public static getDerivedStateFromError(error: any) {
    return { hasError: true }
  }
  public constructor(props: Props) {
    super(props)
    this.state = { hasError: false }
  }
  public componentDidCatch(error: any, info: any) {
    console.log(error, info)
  }
  public render() {
    if (this.state.hasError) {
      return <ErrorPage message={'页面错误'}></ErrorPage>
    }
    return this.props.children
  }
}
export default ErrorBoundary
